package com.dsmclub.myfootballds;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;

public class GridItemAdapter extends BaseAdapter {
	private Context context;
	private ArrayList<Scores.ScoreRecord> scores;
 
	public GridItemAdapter(Context context, ArrayList<Scores.ScoreRecord> scores) {
		this.context = context;
		this.scores = scores;
	}
 
	public View getView(int position, View convertView, ViewGroup parent) {
 
		LayoutInflater inflater = (LayoutInflater) context
			.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 
		View gridView;
 
		if (convertView == null) {
 
			gridView = new View(context);
 
			// get layout from mobile.xml
			gridView = inflater.inflate(R.layout.grid_item, null);
 
			// setting data from scores
			TextView textView = (TextView) gridView.findViewById(R.id.grid_item_time);
			textView.setText(((Scores.ScoreRecord)scores.get(position)).time);
			
			textView = (TextView) gridView.findViewById(R.id.grid_item_team1_name);
			textView.setText(((Scores.ScoreRecord)scores.get(position)).team1.name);
 
			ImageView imageView = (ImageView) gridView.findViewById(R.id.grid_item_team1_logo);
			int logo_id = ((Scores.ScoreRecord)scores.get(position)).team1.logo;
			if (logo_id == -1)
				imageView.setImageResource(android.R.color.transparent); // This will make default image invisible
			else
				imageView.setImageResource((logo_id == -1 ? R.drawable.logo_android_sphere : logo_id));
			
			textView = (TextView) gridView.findViewById(R.id.grid_item_score);
			textView.setText(((Scores.ScoreRecord)scores.get(position)).score);
			
			textView = (TextView) gridView.findViewById(R.id.grid_item_team2_name);
			textView.setText(((Scores.ScoreRecord)scores.get(position)).team2.name);
 
			imageView = (ImageView) gridView.findViewById(R.id.grid_item_team2_logo);
			logo_id = ((Scores.ScoreRecord)scores.get(position)).team2.logo;
			if (logo_id == -1)
				imageView.setImageResource(android.R.color.transparent); // This will make default image invisible
			else
				imageView.setImageResource((logo_id == -1 ? R.drawable.logo_android_terminator : logo_id));
 
		} else {
			gridView = (View) convertView;
		}
 
		return gridView;
	}
 
	//@Override 
	public int getCount() {
		return scores.size();
	}
 
	//@Override 
	public Object getItem(int position) {
		return null;
	}
 
	//@Override
	public long getItemId(int position) {
		return 0;
	}
 
}